﻿
using System.Collections.Generic;
using System.Linq;
using QFramework;
using UnityEngine;
using XCZProject;

public class ExpUpgradeSystem:AbstractSystem
{
    public List<ExpUpgradeItem> Items { get; } = new List<ExpUpgradeItem>();//升级按钮列表

    public Dictionary<string, ExpUpgradeItem> Dictionary = new Dictionary<string, ExpUpgradeItem>();

    // 超级武器的配对表
    public Dictionary<string, string> Pairs = new Dictionary<string, string>()
    {
        {"simple_sword","simple_critical"},
        {"simple_bomb","simple_fly_count"},
        {"simple_knife","damage_rate"},
        {"basket_ball","movement_speed_rate"},
        {"rotate_sword","simple_exp"},
        
        {"simple_critical","simple_sword"},
        {"simple_fly_count","simple_bomb"},
        {"damage_rate","simple_knife"},
        {"movement_speed_rate","basket_ball"},
        {"simple_exp","rotate_sword"},
    };

    public Dictionary<string, BindableProperty<bool>> PairedProperties = new Dictionary<string, BindableProperty<bool>>()
    {
        {"simple_sword",Global.SuperSword},
        {"simple_bomb",Global.SuperBomb},
        {"simple_knife",Global.SuperKnife},
        {"basket_ball",Global.SuperBasketBall},
        {"rotate_sword",Global.SuperRotateSword},
    };
    
    public ExpUpgradeItem Add(ExpUpgradeItem item)
    {
        Items.Add(item);
        return item;
    }
    
    protected override void OnInit()
    {
        ResetData();
        Global.Lv.Register(lv =>
        {
            //Debug.Log("测试执行");
            Roll();
        });
    }

    public void ResetData()
    {
        //Debug.Log("开始初始化经验系统");
        // 清除所有Items，重新加载进来
        Items.Clear();

        var configSystem = this.GetSystem<ConfigSystem>();
        var abilityConfig = configSystem.AbilityConfig;

        //Debug.Log(configSystem);
        foreach (var ability in abilityConfig.DataList)
        {
            // 获取技能ID
            var abilityId = ability.AbilityId;
            // 根据技能ID获取到该技能的升级信息
            var upgradeItemList=configSystem.AbilityUpgradeConfig.DataList.FindAll(item => item.AbilityId == abilityId);

            Dictionary<int, string> tempDesDic = new Dictionary<int, string>();
            foreach (var abilityUpgrade in upgradeItemList)
            {
                tempDesDic.Add(abilityUpgrade.Level, abilityUpgrade.Desc);
            }

            var item = new ExpUpgradeItem(ability.IsWeapon)
                .Withkey(ability.NameEn)
                .WithName(ability.Name)
                .WithIconName(ability.IconName)
                .WithPairedName(ability.PairedName)
                .WithPairedIconName(ability.PairedIconName)
                .WithPairedDescription(ability.PairedDesc)
                .WithDescription(tempDesDic)
                .WithMaxLevel(ability.MaxLevel)
                .OnUpgrade((item, level) =>
                {
                    // 找到当前等级对应的技能加成
                    var abilityUpgrade = upgradeItemList.FirstOrDefault(item => item.Level == level&&item.AbilityId==ability.AbilityId);
                    switch (ability.AbilityId)
                    {
                        case 1001:
                            if (abilityUpgrade.Level==1) Global.SimpleSwordUnlocked.Value = true;
                            Global.SimpleAbilityDamage.Value = abilityUpgrade.Damage;
                            Global.SimpleSwordCount.Value = abilityUpgrade.Count;
                            Global.SimpleAbilityDuration.Value = abilityUpgrade.Duration;
                            Global.SimpleSwordRange.Value = abilityUpgrade.Range;
                            break;
                        case 1002:
                            if (abilityUpgrade.Level==1) Global.RotateSwordUnlocked.Value = true;
                            Global.RotateSwordDamage.Value = abilityUpgrade.Damage;
                            Global.RotateSwordCount.Value = abilityUpgrade.Count;
                            Global.RotateSwordRange.Value = abilityUpgrade.Range;
                            Global.RotateSwordSpeed.Value = abilityUpgrade.Speed;
                            break;
                        case 1003:
                            if (abilityUpgrade.Level==1) Global.BombUnlocked.Value = true;
                            Global.BombDamage.Value = abilityUpgrade.Damage;
                            Global.BombPercent.Value = abilityUpgrade.Percent;
                            break;
                        case 1004:
                            if (abilityUpgrade.Level==1) Global.SimpleKnifeUnlocked.Value = true;
                            Global.SimpleKnifeDamage.Value = abilityUpgrade.Damage;
                            Global.SimpleKnifeCount.Value = abilityUpgrade.Count;
                            Global.SimpleKnifeDuration.Value = abilityUpgrade.Duration;
                            break;
                        case 1005:
                            if (abilityUpgrade.Level==1) Global.BasketBallUnlocked.Value = true;
                            Global.BasketBallDamage.Value = abilityUpgrade.Damage;
                            Global.BasketBallCount.Value = abilityUpgrade.Count;
                            Global.BasketBallSpeed.Value = abilityUpgrade.Speed;
                            break;
                        case 1006:
                            Global.CriticalRate.Value = abilityUpgrade.CriticalRate;
                            break;
                        case 1007:
                            Global.DamageRate.Value = abilityUpgrade.DamageRate;
                            break;
                        case 1008:
                            Global.SimpleFlyCount.Value = abilityUpgrade.SimpleFlyCount;
                            break;
                        case 1009:
                            Global.MovementSpeedRate.Value = abilityUpgrade.MovementSpeedRate;
                            break;
                        case 1010:
                            Global.CollectableArea.Value = abilityUpgrade.CollectableArea;
                            break;
                        case 1011:
                            Global.ExpPercent.Value = abilityUpgrade.Percent;
                            break;
                    }
                });
            Add(item);

        }
        
        
        // 把Items转换为字典
        Dictionary = Items.ToDictionary(i => i.Key);
        

        // Add(new ExpUpgradeItem(true))
        //     .Withkey("simple_sword")
        //     .WithName("剑")
        //     .WithIconName("simple_sword_icon")
        //     .WithPairedName("合成后的剑")
        //     .WithPairedIconName("paired_simple_sword_icon")
        //     .WithPairedDescription("攻击力翻倍 攻击范围翻倍")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"剑Lv{lv}:攻击身边的敌人",
        //             2 => $"剑Lv{lv}:\n攻击力+3 数量+2",
        //             3 => $"剑Lv{lv}:\n攻击力+2 间隔-0.25s",
        //             4 => $"剑Lv{lv}:\n攻击力+2 间隔-0.25s",
        //             5 => $"剑Lv{lv}:\n攻击力+3 数量+2",
        //             6 => $"剑Lv{lv}:\n范围+1 间隔-0.25s",
        //             7 => $"剑Lv{lv}:\n攻击力+3 数量+2",
        //             8 => $"剑Lv{lv}:\n攻击力+3 范围+1",
        //             9 => $"剑Lv{lv}:\n攻击力+3 间隔-0.25s",
        //             10 => $"剑Lv{lv}:\n攻击力+3 数量+2",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(10)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.SimpleSwordUnlocked.Value = true;
        //                 break;
        //             case 2:
        //                 Global.SimpleAbilityDamage.Value += 3;
        //                 Global.SimpleSwordCount.Value += 2;
        //                 break;
        //             case 3:
        //                 Global.SimpleAbilityDamage.Value += 2;
        //                 Global.SimpleAbilityDuration.Value-=0.25f;
        //                 break;
        //             case 4:
        //                 Global.SimpleAbilityDamage.Value += 2;
        //                 Global.SimpleAbilityDuration.Value-=0.25f;
        //                 break;
        //             case 5:
        //                 Global.SimpleAbilityDamage.Value += 2;
        //                 Global.SimpleSwordCount.Value += 2;
        //                 break;
        //             case 6:
        //                 Global.SimpleSwordRange.Value += 1;
        //                 Global.SimpleAbilityDuration.Value-=0.25f;
        //                 break;
        //             case 7:
        //                 Global.SimpleAbilityDamage.Value += 3;
        //                 Global.SimpleSwordCount.Value += 2;
        //                 break;
        //             case 8:
        //                 Global.SimpleAbilityDamage.Value += 3;
        //                 Global.SimpleSwordRange.Value += 1;
        //                 break;
        //             case 9:
        //                 Global.SimpleAbilityDamage.Value += 3;
        //                 Global.SimpleAbilityDuration.Value-=0.25f;
        //                 break;
        //             case 10:
        //                 Global.SimpleAbilityDamage.Value += 3;
        //                 Global.SimpleSwordCount.Value += 2;
        //                 break;
        //         }
        //     });
        //
        // Add(new ExpUpgradeItem(true))
        //     .Withkey("rotate_sword")
        //     .WithName("守卫剑")
        //     .WithIconName("rotate_sword_icon")
        //     .WithPairedName("合成后的守卫剑")
        //     .WithPairedIconName("paired_rotate_sword_icon")
        //     .WithPairedDescription("攻击力翻倍 攻击范围翻倍")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"守卫剑Lv{lv}:\n生成一把守卫剑",
        //             2 => $"守卫剑Lv{lv}:\n攻击力+3 数量+2",
        //             3 => $"守卫剑Lv{lv}:\n攻击力+2 范围+1 数量+1",
        //             4 => $"守卫剑Lv{lv}:\n攻击力+2  数量+1 穿透+1",
        //             5 => $"守卫剑Lv{lv}:\n攻击力+3 数量+2",
        //             6 => $"守卫剑Lv{lv}:\n范围+1 数量+1",
        //             7 => $"守卫剑Lv{lv}:\n攻击力+3 数量+2",
        //             8 => $"守卫剑Lv{lv}:\n攻击力+3 数量+1",
        //             9 => $"守卫剑Lv{lv}:\n攻击力+3 间隔-0.1s",
        //             10 => $"守卫剑Lv{lv}:\n攻击力+3 数量+2",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(10)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.RotateSwordUnlocked.Value = true;
        //                 break;
        //             case 2:
        //                 Global.RotateSwordDamage.Value += 3;
        //                 Global.RotateSwordCount.Value += 2;
        //                 break;
        //             case 3:
        //                 Global.RotateSwordDamage.Value += 2;
        //                 Global.RotateSwordRange.Value+=1f;
        //                 Global.RotateSwordCount.Value += 1;
        //                 break;
        //             case 4:
        //                 Global.RotateSwordDamage.Value += 2;
        //                 Global.RotateSwordRange.Value+=1f;
        //                 Global.RotateSwordCount.Value += 1;
        //                 break;
        //             case 5:
        //                 Global.RotateSwordDamage.Value += 2;
        //                 Global.RotateSwordCount.Value += 2;
        //                 break;
        //             case 6:
        //                 Global.RotateSwordRange.Value+=1f;
        //                 Global.RotateSwordCount.Value += 1;
        //                 break;
        //             case 7:
        //                 Global.RotateSwordDamage.Value += 3;
        //                 Global.RotateSwordCount.Value += 2;
        //                 break;
        //             case 8:
        //                 Global.RotateSwordDamage.Value += 3;
        //                 Global.RotateSwordCount.Value += 1;
        //                 break;
        //             case 9:
        //                 Global.RotateSwordDamage.Value += 3;
        //                 Global.RotateSwordRange.Value+=1f;
        //                 break;
        //             case 10:
        //                 Global.RotateSwordDamage.Value += 3;
        //                 Global.RotateSwordCount.Value += 2;
        //                 break;
        //         }
        //     });
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("simple_bomb")
        //     .WithName("炸弹")
        //     .WithIconName("bomb_icon")
        //     .WithPairedName("合成后的炸弹")
        //     .WithPairedIconName("paired_bomb_icon")
        //     .WithPairedDescription("每隔 15 秒爆炸一次")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"炸弹Lv{lv}:\n攻击全部敌人（怪物掉落）",
        //             2 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             3 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             4 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             5 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             6 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             7 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             8 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             9 => $"炸弹Lv{lv}:\n掉落概率+5% 攻击力+5",
        //             10 => $"炸弹Lv{lv}:\n掉落概率+10% 攻击力+5",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(10)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.BombUnlocked.Value = true;
        //                 break;
        //             case 2:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 3:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 4:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 5:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 6:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 7:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 8:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 9:
        //                 Global.BombPercent.Value += 0.05f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //             case 10:
        //                 Global.BombPercent.Value += 0.1f;
        //                 Global.BombDamage.Value += 5;
        //                 break;
        //         }
        //         
        //         
        //     }); 
        //
        // Add(new ExpUpgradeItem(true))
        //     .Withkey("simple_knife")
        //     .WithName("飞刀")
        //     .WithIconName("simple_knife_icon")
        //     .WithPairedName("合成后的飞刀")
        //     .WithPairedIconName("paired_simple_knife_icon")
        //     .WithPairedDescription("攻击力翻倍")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"小刀Lv{lv}:\n向最近的敌人发射一把飞刀",
        //             2 => $"小刀Lv{lv}:\n攻击力+3 数量+2",
        //             3 => $"小刀Lv{lv}:\n攻击力+2 间隔-0.1s 数量+1",
        //             4 => $"小刀Lv{lv}:\n攻击力+2 间隔-0.1s 数量+1 穿透+1",
        //             5 => $"小刀Lv{lv}:\n攻击力+3 数量+2",
        //             6 => $"小刀Lv{lv}:\n间隔-0.1s 数量+1",
        //             7 => $"小刀Lv{lv}:\n攻击力+3 数量+2",
        //             8 => $"小刀Lv{lv}:\n攻击力+3 数量+1",
        //             9 => $"小刀Lv{lv}:\n攻击力+3 间隔-0.1s",
        //             10 => $"小刀Lv{lv}:\n攻击力+3 数量+2",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(10)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.SimpleKnifeUnlocked.Value = true;
        //                 break;
        //             case 2:
        //                 Global.SimpleKnifeDamage.Value += 3;
        //                 Global.SimpleKnifeCount.Value += 2;
        //                 break;
        //             case 3:
        //                 Global.SimpleKnifeDamage.Value += 2;
        //                 Global.SimpleKnifeDuration.Value-=0.1f;
        //                 Global.SimpleKnifeCount.Value += 1;
        //                 break;
        //             case 4:
        //                 Global.SimpleKnifeDamage.Value += 2;
        //                 Global.SimpleKnifeDuration.Value-=0.1f;
        //                 Global.SimpleKnifeAttackCount.Value++;
        //                 Global.SimpleKnifeCount.Value += 1;
        //                 break;
        //             case 5:
        //                 Global.SimpleKnifeDamage.Value += 2;
        //                 Global.SimpleKnifeCount.Value += 2;
        //                 break;
        //             case 6:
        //                 Global.SimpleKnifeDuration.Value-=0.1f;
        //                 Global.SimpleKnifeCount.Value += 1;
        //                 break;
        //             case 7:
        //                 Global.SimpleKnifeDamage.Value += 3;
        //                 Global.SimpleKnifeCount.Value += 2;
        //                 break;
        //             case 8:
        //                 Global.SimpleKnifeDamage.Value += 3;
        //                 Global.SimpleKnifeCount.Value += 1;
        //                 break;
        //             case 9:
        //                 Global.SimpleKnifeDamage.Value += 3;
        //                 Global.SimpleKnifeDuration.Value-=0.1f;
        //                 break;
        //             case 10:
        //                 Global.SimpleKnifeDamage.Value += 3;
        //                 Global.SimpleKnifeCount.Value += 2;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(true))
        //     .Withkey("basket_ball")
        //     .WithName("篮球")
        //     .WithIconName("ball_icon")
        //     .WithPairedName("合成后的篮球")
        //     .WithPairedIconName("paired_ball_icon")
        //     .WithPairedDescription("攻击力翻倍 体积变大")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"篮球Lv{lv}:\n在屏幕内反弹的篮球",
        //             2 => $"篮球Lv{lv}:\n攻击力+3",
        //             3 => $"篮球Lv{lv}:\n数量+2",
        //             4 => $"篮球Lv{lv}:\n攻击力+3",
        //             5 => $"篮球Lv{lv}:\n数量+1",
        //             6 => $"篮球Lv{lv}:\n攻击力+3",
        //             7 => $"篮球Lv{lv}:\n速度+20%",
        //             8 => $"篮球Lv{lv}:\n攻击力+3",
        //             9 => $"篮球Lv{lv}:\n速度+20%",
        //             10 => $"篮球Lv{lv}:\n数量+1",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(10)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.BasketBallUnlocked.Value = true;
        //                 break;
        //             case 2:
        //                 Global.BasketBallDamage.Value += 3;
        //                 break;
        //             case 3:
        //                 Global.BasketBallCount.Value += 2;
        //                 break;
        //             case 4:
        //                 Global.BasketBallDamage.Value += 3;
        //                 break;
        //             case 5:
        //                 Global.BasketBallCount.Value += 2;
        //                 break;
        //             case 6:
        //                 Global.BasketBallDamage.Value += 3;
        //                 break;
        //             case 7:
        //                 Global.BasketBallSpeed.Value *=0.2f;
        //                 break;
        //             case 8:
        //                 Global.BasketBallDamage.Value += 3;
        //                 break;
        //             case 9:
        //                 Global.BasketBallSpeed.Value *=0.2f;
        //                 break;
        //             case 10:
        //                 Global.BasketBallCount.Value += 2;
        //                 break;
        //         }
        //         
        //         
        //     });
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("simple_critical")
        //     .WithName("暴击")
        //     .WithIconName("critical_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"暴击Lv{lv}:\n每次伤害 15%概率暴击",
        //             2 => $"暴击Lv{lv}:\n每次伤害 28%概率暴击",
        //             3 => $"暴击Lv{lv}:\n每次伤害 43%概率暴击",
        //             4 => $"暴击Lv{lv}:\n每次伤害 50%概率暴击",
        //             5 => $"暴击Lv{lv}:\n每次伤害 80%概率暴击",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(5)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.CriticalRate.Value = 0.15f;
        //                 break;
        //             case 2:
        //                 Global.CriticalRate.Value = 0.28f;
        //                 break;
        //             case 3:
        //                 Global.CriticalRate.Value = 0.43f;
        //                 break;
        //             case 4:
        //                 Global.CriticalRate.Value = 0.5f;
        //                 break;
        //             case 5:
        //                 Global.CriticalRate.Value = 0.8f;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("damage_rate")
        //     .WithName("伤害率")
        //     .WithIconName("damage_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"伤害率Lv{lv}:\n伤害提升10%",
        //             2 => $"伤害率Lv{lv}:\n伤害提升20%",
        //             3 => $"伤害率Lv{lv}:\n伤害提升30%",
        //             4 => $"伤害率Lv{lv}:\n伤害提升40%",
        //             5 => $"伤害率Lv{lv}:\n伤害提升50%",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(5)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.DamageRate.Value = 1.1f;
        //                 break;
        //             case 2:
        //                 Global.DamageRate.Value = 1.2f;
        //                 break;
        //             case 3:
        //                 Global.DamageRate.Value = 1.3f;
        //                 break;
        //             case 4:
        //                 Global.DamageRate.Value = 1.4f;
        //                 break;
        //             case 5:
        //                 Global.DamageRate.Value = 1.5f;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("simple_fly_count")
        //     .WithName("飞射物")
        //     .WithIconName("fly_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"飞行物Lv{lv}:\n额外增加 1个",
        //             2 => $"飞行物Lv{lv}:\n额外增加 2个",
        //             3 => $"飞行物Lv{lv}:\n额外增加 3个",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(3)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.SimpleFlyCount.Value++;
        //                 break;
        //             case 2:
        //                 Global.SimpleFlyCount.Value++;
        //                 break;
        //             case 3:
        //                 Global.SimpleFlyCount.Value++;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("movement_speed_rate")
        //     .WithName("移动速度")
        //     .WithIconName("movement_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"移动速度Lv{lv}:\n提升 20%",
        //             2 => $"移动速度Lv{lv}:\n提升 40%",
        //             3 => $"移动速度Lv{lv}:\n提升 60%",
        //             4 => $"移动速度Lv{lv}:\n提升 80%",
        //             5 => $"移动速度Lv{lv}:\n提升 100%",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(5)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.MovementSpeedRate.Value = 1.2f;
        //                 break;
        //             case 2:
        //                 Global.MovementSpeedRate.Value = 1.4f;
        //                 break;
        //             case 3:
        //                 Global.MovementSpeedRate.Value = 1.6f;
        //                 break;
        //             case 4:
        //                 Global.MovementSpeedRate.Value = 1.8f;
        //                 break;
        //             case 5:
        //                 Global.MovementSpeedRate.Value = 2.0f;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("simple_collectable_area")
        //     .WithName("拾取范围")
        //     .WithIconName("collectable_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"拾取范围Lv{lv}:\n额外增加 100%",
        //             2 => $"拾取范围Lv{lv}:\n额外增加 200%",
        //             3 => $"拾取范围Lv{lv}:\n额外增加 300%",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(3)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.CollectableArea.Value*=2f;
        //                 break;
        //             case 2:
        //                 Global.CollectableArea.Value*=3f;
        //                 break;
        //             case 3:
        //                 Global.CollectableArea.Value*=4f;
        //                 break;
        //         }
        //     }); 
        //
        // Add(new ExpUpgradeItem(false))
        //     .Withkey("simple_exp")
        //     .WithName("经验值")
        //     .WithIconName("exp_icon")
        //     .WithDescription(lv =>
        //     {
        //         return lv switch
        //         {
        //             1 => $"经验掉落概率Lv{lv}:\n提升 5%",
        //             2 => $"经验掉落概率Lv{lv}:\n提升 10%",
        //             3 => $"经验掉落概率Lv{lv}:\n提升 20%",
        //             4 => $"经验掉落概率Lv{lv}:\n提升 30%",
        //             5 => $"经验掉落概率Lv{lv}:\n提升 50%",
        //             _ => null
        //         };
        //     })
        //     .WithMaxLevel(5)
        //     .OnUpgrade((item, level) =>
        //     {
        //         switch (level)
        //         {
        //             case 1:
        //                 Global.AdditonalExpPercent.Value = 0.05f;
        //                 break;
        //             case 2:
        //                 Global.AdditonalExpPercent.Value = 0.1f;
        //                 break;
        //             case 3:
        //                 Global.AdditonalExpPercent.Value = 0.2f;
        //                 break;
        //             case 4:
        //                 Global.AdditonalExpPercent.Value = 0.3f;
        //                 break;
        //             case 5:
        //                 Global.AdditonalExpPercent.Value = 0.5f;
        //                 break;
        //         }
        //     });

        // 把Items转换为字典
        //Dictionary = Items.ToDictionary(i => i.Key);

        // // 攻击力升级Item加载
        //     var simpleDamageLv1=Add(new ExpUpgradeItem()
        //         .Withkey("simple_damage")
        //         .WithDescription(lv=>$"攻击力提升 Lv{lv}") // func<int,string> 通过lv来返回一个string字符串
        //         .WithMaxLevel(10)
        //         .OnUpgrade((_,level) =>
        //         {
        //             if (level==1)
        //             {
        //                 // 等级1是默认的，暂不做处理
        //             }
        //             Global.SimpleAbilityDamage.Value *= 1.5f;
        //         })
        //     );
        //     
        //     // 攻击频率Item加载
        //     var simpleDurationLv1=Add(new ExpUpgradeItem()
        //         .Withkey("simple_duration")
        //         .WithDescription(lv=>$"攻击频率提升 Lv{lv}")
        //         .WithMaxLevel(10)
        //         .OnUpgrade((_,level) =>
        //         {
        //             if (level==1)
        //             {
        //                 // 等级1是默认的，暂不做处理
        //             }
        //             Global.SimpleAbilityDuration.Value *= 0.8f;
        //         })
        //     );
        //     

    }

    /// <summary>
    /// 当升级时，会在所有Item列表中随机一个展示出来
    /// </summary>
    public void Roll()
    {
        // 设置所有Item的Visible为false，在随机后再设置为true，为true的则展示
        foreach (var expUpgradeItem in Items)
        {
            expUpgradeItem.Visible.Value = false;
        }
        // 从Items中随机一个Item，并且这个item是没有升级完成的（也就是没有达到最大等级）
        // var item = Items.Where(item => !item.UpgradeFinish).ToList().GetRandomItem();

        var itemList = Items.Where(item => !item.UpgradeFinish).ToList();
        if (itemList.Count>=4)
        {
            itemList.GetAndRemoveRandomItem().Visible.Value = true;
            itemList.GetAndRemoveRandomItem().Visible.Value = true;
            itemList.GetAndRemoveRandomItem().Visible.Value = true;
            itemList.GetAndRemoveRandomItem().Visible.Value = true;
        }
        else
        {
            foreach (var item in itemList)
            {
                item.Visible.Value = true;
            }
        }
    }
}
